package service

import (
	"fitness/internal/dao"
	"fitness/internal/entity/system"
	"fitness/pkg/utils/R"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
)

type LogService struct {
	LogDao *dao.LogDao
	Log    *zap.Logger
}

func NewLogService(LogDao *dao.LogDao, Log *zap.Logger) *LogService {
	return &LogService{
		LogDao: LogDao,
		Log:    Log,
	}
}

func (s *LogService) ListPagedLogs(c *gin.Context) {
	var logPageQuery system.LogPageQuery
	err := c.ShouldBindQuery(&logPageQuery)
	if err != nil {
		// 如果转换失败，返回错误响应
		s.Log.Error("日志查询绑定失败", zap.Error(err))
		c.JSON(http.StatusOK, R.ReturnFailMsg("日志查询绑定失败"))
		return
	}

	form, err := s.LogDao.ListPagedLogs(logPageQuery)
	if err != nil {
		c.JSON(http.StatusOK, R.ReturnFailMsg(err.Error()))
		return
	}
	c.JSON(http.StatusOK, R.ReturnSuccess(form))
}
